
package com.hjm.project.ShopOrder.ShopOrder.api;

import com.alibaba.fastjson.JSON;
import com.hjm.project.ShopOrder.ShopOrder.utils.HttpUtils;
import com.hjm.project.ShopOrder.ShopOrder.utils.JsonUtils;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 *********************************************************.<br>
 * [类名] Express <br>
 * [描述] (快递100) <br>
 * [作者] maker<br>
 *********************************************************.<br>
 */
public class Express {
	private static final String CUSTOMER = "F72EEEC223BFCD7F57F1BE4C5D23201B";
	private static final String KEY = "yyCkKXEC5133";
	
	
	
	/**
	 * 
	 *********************************************************.<br>
	 * [方法] send <br>
	 * [参数] (com 快递编号   num 快递单号) <br>
	 * [返回] String <br>
	 * [作者] Gd
	 *********************************************************.<br>
	 */
	public static List<Map<String, Object>> send(String com,String num){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("com", com);
		map.put("num", num);
	    Object param = JSON.toJSONString(map);
		String sign = DigestUtils.md5Hex((param+KEY+CUSTOMER).getBytes()).toUpperCase();
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("param",param);
		params.put("sign",sign);
		params.put("customer",CUSTOMER);
		String url = "http://poll.kuaidi100.com/poll/query.do?customer="+CUSTOMER+"&sign="+sign + "&param="+param;
		String doPost = "";
		try {
			 doPost = HttpUtils.doGet(url,null);

			 Map<String, Object> jsonToMap = JsonUtils.jsonToMap(doPost);
				List<Map<String, Object>> data = (List<Map<String, Object>>)jsonToMap.get("data");
				if (data == null || data.size() == 0) {
					return null;
				} else {
					return data;
				}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null; 
	}
	


		public static void main(String[] args) {
			
			
			//  http://poll.kuaidi100.com/poll/query.do?customer=F72EEEC223BFCD7F57F1BE4C5D23201B&sign=8176B0EFB097636568CA4EC4C9874133&param={"com":"yunda","num":"3950055201640","from":"","phone":"","to":"","resultv2":"0","show":"0","order":"desc"}

			List<Map<String, Object>> list = Express.send("zhongtong", "75353570388316");
			System.out.println(list);
			
			/*
			String s  = "5000.00";
			int indexOf = s.indexOf(".");
			System.out.println(indexOf);
			String substring = s.substring(0, indexOf);
			System.out.println(substring);*/
			
		}

}

	